package rstk.resources;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author AJoyWatkins
 * @version 3.21.2011
 */
public class RSTKPanel extends JPanel{
	private final Color border1 = new Color(109,105,93); //Main outside border
	private final Color border2 = new Color(41,40,32); //Secondary inside border
	private final Color border3 = new Color(82,73,66); //Main Body Border
	private final Color topCorner = new Color(156,157,152); //One Pixel
	private final Color bottomCorner = new Color(44,41,34); //One Pixel
	private final Color bottomDiaginal = new Color(82,74,61); //above and beside bottom corner
	private final Color main = new Color(41,36,24);
	private final Color[] gradient = { new Color(43,41,31),
			new Color(42,38,27),
			new Color(39,32,24),
			new Color(33,30,23),
			new Color(31,27,18),
			new Color(26,23,16),
			new Color(22,17,13),
			new Color(16,13,8),
			new Color(9,10,5),
			new Color(8,7,2),
			new Color(9,10,5),
			new Color(7,8,2),
			new Color(9,10,5),
			new Color(7,8,2),
			new Color(9,10,2),
			new Color(22,17,13),
			border2};
	int w;
	int h;
	/**
	 * Creates a panel that has a background image the size of height and width
	 * 
	 * @param not null height of the panel background
	 * @param not null width of the panel background
	 */
	public RSTKPanel(int height, int width){
		super();
		h = height;
		w = width;
	}
	/**
	 * Updates the height and width of the background image of the panel
	 * @param height - not null integer that is the desired height for the 
	 * 					background image
	 * @param width - not null integer that is the desired height for the
	 * 					background image
	 */
	public void updateSize(int height, int width){
		h = height;
		w = width;
	}
	/**
	 * Paints the standard background
	 * 
	 * @param g - not null graphics object
	 */
	@Override
	public void paint(Graphics g) {
		/*
		 * This method is very messy and can be hard to follow
		 * 
		 * Currently this has not unit tests (so you must test manually)
		 */
		h=h-1;
		w=w-1;
		int x = 0;
		int y = 0;

		//Paint Border 1
		g.setColor(border1);
		g.fillRect(x+1, y, w-1, 1);
		g.fillRect(x+2, h, w-3, 1);
		g.fillRect(x, y+1, 1, h-2);
		g.fillRect(w, y+1, 1, h-2);

		//Paint Top Corners
		g.setColor(topCorner);
		g.fillRect(x, y, 2, 1);
		g.fillRect(x, y, 1, 2);
		g.fillRect(w-1, y, 2, 1);
		g.fillRect(w,y,1,2);


		//Paint Bottom Corners
		g.setColor(bottomCorner);
		g.fillRect(x, h, 1, 1);
		g.fillRect(w,h,1,1);

		//Paint Bottom Diagional
		g.setColor(bottomDiaginal);
		g.fillRect(x, h-1, 1, 1);
		g.fillRect(y+1, h, 1, 1);
		g.fillRect(w, h-1, 1, 1);
		g.fillRect( w-1, h, 1, 1);

		//setting up new bounds
		x = x+1;
		y = y+1;
		h = h-1;
		w = w-1;

		//Paint Border 2
		g.setColor(border2);
		g.fillRect(x,y,w,1);
		g.fillRect(x,h,w,1);
		g.fillRect(x, y, 1, h);
		g.fillRect(w, y, 1, h);

		//Top Corner Finishing Touches
		g.setColor(border1);
		g.fillRect(x,y,2,1);
		g.fillRect(x, y+1, 1, 1);
		g.fillRect(w-1, y, 2, 1);
		g.fillRect(w, y+1, 1, 1);

		//Bottom Corner Finishing Touches
		g.fillRect(x, h-1, 2, 1);
		g.fillRect(x,h,2,1);
		g.fillRect(w,h-1,2,1);
		g.fillRect(w-1, h, 2, 1);

		x = x+1;
		y = y+1;
		h = h-1;
		w = w-1;

		//Paint Top Gradient
		for(int i = 0; i<gradient.length; i++){
			int currY= y + i;
			g.setColor(gradient[i]);
			g.fillRect(x, currY, w-1, 1);
		}

		y = y+gradient.length;
		int newH = h-gradient.length-1;

		//Paint Border 3
		g.setColor(border3);
		g.fillRect(x,y,w-1,1);
		g.fillRect(x+1,h,w-3,1);
		g.fillRect(x, y, 1, newH-1);
		g.fillRect(w, y, 1, newH-1);

		//Finishing Touches Border
		g.setColor(border2);
		g.fillRect(x, h, 1, 1);
		g.fillRect(w,h,1,1);

		x = x+1;
		y = y+1;
		w = w-3;
		newH = newH-2;

		//Paint main area
		g.setColor(main);
		g.fillRect(x, y, w, newH);

	}

	


}